package com.android.equipment.net;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.android.equipment.net.callbck.JsonCallback;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;


public class OkUtil {
    /**
     * @param url
     * @param callback
     * @param <T>
     */
    public static <T> void getRequest(String url, JsonCallback<T> callback) {
        OkGo.<T>get(url)
                .tag("OkUtil")
                .execute(callback);
    }

    /**
     * @param url
     * @param params
     * @param callback
     * @param <T>
     */
    public static <T> void getRequest(String url, HttpParams params, JsonCallback<T> callback) {
        OkGo.<T>get(url)
                .tag("getRequest")
                .params(params)
                .execute(callback);
    }

    /**
     * @param url
     * @param tag
     * @param params
     * @param callback
     * @param <T>
     */
    public static <T> void getRequest(String url, Object tag, HttpParams params, JsonCallback<T> callback) {
        OkGo.<T>get(url)
                .tag(tag)
                .params(params)
                .execute(callback);
    }

    public static <T> void postRequest(String url, Object tag, Map<String, String> params, JsonCallback<T> callback) {
        OkGo.<T>post(url)
                .tag(tag)
                .params(params)
                .execute(callback);
    }

    public static <T> void postRequest(String url, HttpParams params, JsonCallback<T> callback) {
        OkGo.<T>post(url)
                .tag("OkUtil")
                .params(params)
                .execute(callback);
    }

    public static <T> void postFileRequest(String url, HttpParams params, JsonCallback<T> callback) {
        OkGo.<T>post(url)
                .tag("OkUtil")
                .params(params)
                .isMultipart(true)
                .execute(callback);
    }
   public static <T> void postFileRequest1(String url, String string, MediaType mediaType, JsonCallback<T> callback) {
        OkGo.<T>post(url)
                .tag("OkUtil")
                .upString(string,mediaType)
                .execute(callback);
    }

    public static <T> void postBodyRequest(String url, RequestBody requestBody, JsonCallback<T> callback) {
        OkGo.<T>post(url)
                .tag("OkUtil")
                .upRequestBody(requestBody)
                .execute(callback);
    }

    public static <T> void putJsonRequest(String url, String params, JsonCallback<T> callback) {
        OkGo.<T>put(url)
                .tag("OkUtil")
                .upJson(params)
                .execute(callback);
    }

    public static <T> void deleteRequest(String url, JsonCallback<T> callback) {
        OkGo.<T>delete(url)
                .tag("OkUtil")
                .execute(callback);
    }


    public static <T> void postUpStringRequest(String url, String jsonParams, JsonCallback<T> callback){
        OkGo.<T>post(url)
                .tag("OkUtil")
                .upString(jsonParams)
                .execute(callback);
    }



}
